{% extends "public/layout.html" %}

{% block breadcrumb %}
     <ol class="breadcrumb">
        <li>
            <a href="{% url 'index' %}">首页</a>
        </li>
         <li>
             <a>发布系统</a>
         </li>
        <li class="active">
            <strong>申请列表</strong>
        </li>
    </ol>
{% endblock %}


{% block body %}
<div  class="wrapper wrapper-content animated fadeInRight">
<div class="row">
      <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5> 上线列表 </h5>
                </div>

                <div class="ibox-content">
                    <div class="">
                        <form id="search_form" method="get" action="" class="pull-right mail-search">
                            <div class="input-group">
                                <input type="text" class="form-control input-sm" id="search_input" name="search_keywords" placeholder="项目名|更新详情|版本描述">
                                <div class="input-group-btn">
                                    <button id='search_btn' type="submit" class="btn btn-sm btn-primary">
                                        -搜索-
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
    
                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th class="text-center">项目名称</th>
                                <th class="text-center">项目版本</th>
                                <th class="text-center">版本描述</th>
                                <th class="text-center">发布人</th>
                                <th class="text-center">发布状态</th>
                                <th class="text-center">申请时间</th>
                                <th class="text-center">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for project in page_obj.object_list %}
                            <tr class="gradeX {{ project.id }}">
                                <td class="text-center">{{ project.name }}</td>
                                <td class="text-center"> {{ project.project_version }} </td>
                                <td class="text-center"> {{ project.version_desc}} </td>
                                <td class="text-center"> {{ project.assigned_to.name}} </td>
                                <td class="text-center"><span class="label {% if project.status == 0 %}label-success{% elif project.status == 1 %}label-warning{% endif %}">{{ project.get_status_display}}</span></td>
                                <td class="text-center">{{ project.apply_time}}</td>
                                <td class="text-center">
                                    {% if request.user.id == project.assigned_to_id %}
                                        <a href="{% url 'code_release_status' %}?apply_id={{ project.id }}" class="btn btn-xs btn-info">{% if project.status == 0 %}仿真{% elif project.status == 1 %}上线{% endif %}</a>       
                                    {% else %}
                                        <a href="{% url 'code_release_status' %}?apply_id={{ project.id }}" class="btn btn-xs btn-info">详情</a>
                                    {% endif %}
                                    {% if request.user.id == project.applicant_id  or request.user.id == project.assigned_to_id%}
                                        <button data-id="{{ project.id }}" class="btn btn-xs btn-danger apply-cancel">取消</button>
                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                  
                     <div class="row">
                        <div class="col-sm-6">
                            <div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
                                显示 [{{ p.count }}] 条数据中的 第 [{{ page_obj.start_index }}] 至 [{{ page_obj.end_index }}] 的数据
                            </div>
                        </div>
                        {% include 'public/paginator.html' %}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}
{% block js %}
 <script type="text/javascript">
        $('.apply-cancel').click(function () {
            var apply_id = $(this).attr('data-id');
            swal({
                title: "你确定取消上线?",
                text: "取消上线后，需要重新申请",
                type: "warning",
                showCancelButton: true,
                cancelButtonText:"取消",
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                closeOnConfirm: false
            }, function () {
                $.ajax({
                    type: "POST",
                    url: "{% url 'apply_list' %}",
                    data:{"apply_id": apply_id},
                    success: function(data){
                        console.log(data);
                                swal({
                                    title: "是",
                                    text:"取消成功",
                                    type: "success",
                                    confirmButtonText: "确定"
                                }, function () {
                                    $("."+ apply_id).remove();
                                });
                    }
                });
            });
        })
    </script>
{% endblock %}

